<template>
    <!-- 头部导航 -->
    <van-nav-bar
      title="搜索"
      left-arrow
      @click-left="
        () => {
          $router.back('/');
        }
      "
    />
    <van-search
      v-model="searchvalue"
      shape="round"
      placeholder="请输入搜索关键词"
      @click="search"
    />
    <template v-if="searchDate.length === 0 || searchDate.length == 0">
      <van-empty description="暂无搜索数据" />
    </template>
    <template v-else>
      <van-cell-group v-for="item in searchDate">
        <router-link :to="'/detail/' + item.goods_id">
          <van-cell :title="item.goods_name" />
        </router-link>
      </van-cell-group>
    </template>
</template>

<script setup>
import { ref, watch } from "vue";
import { searchApi } from "@/api/api";
let searchvalue = ref("");

import _ from "lodash";
// import router from "@/router";
let searchDate = ref([]);
watch(
  searchvalue,
  _.debounce((searchvalue) => {
    searchApi(searchvalue).then((res) => {
      console.log("搜索", res);
      searchDate.value = res.data.message;
    });
  }, 1500)
);
</script>

<style lang="scss" scoped>
</style>